<?php

require '../conn.php';

require 'config.php';

require '../inc/function.php';

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title></title>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<link rel="stylesheet" href="../css/admin.css" type="text/css" />

<script type="text/javascript" src="inc/function.js"></script>
 
</head>

<body>

<?php

$n_sid=ReStra($_POST['n_sid']);

$n_order=ReStra($_POST['n_order']);

$n_name=ReStra(trim($_POST['n_name']));
 
if($n_order=='') $n_order=0;   


switch($act){

case 'add':

	$sql="insert into ".$language."_pro_class(n_order,n_sid,n_name) values($n_order,$n_sid,'$n_name')";

	mysql_query($sql);

	Msg('','');

	break;

case 'modify':

	mysql_query("update ".$language."_pro_class set n_order=$n_order,n_sid=$n_sid,n_name='$n_name' where n_id=$id");

	Msg('','');

	break;

case 'delete':

	mysql_query('delete from '.$language.'_pro_class where n_id='.$id);

	mysql_query('delete from '.$language.'_pro where n_class='.$id);

	Msg('','');

	break;

 
	
}

?>

<div id="container">

	<?php

	if ($meter==1){

	$query=mysql_query('select * from '.$language.'_pro_class where n_id='.$id);

	$row=mysql_fetch_array($query);

	?>

    <div class="edit">

      <h1>产品分类管理<a href="javascript:location.reload();">刷新</a></h1>

      <form name="form1" method="post" action="?act=modify&id=<?php echo $id ?>" onsubmit="return CheckProClass(this);">

        <table width="100%" border="0" cellpadding="0" cellspacing="0">

          <tr>

            <td class="edit_title">分类名称：</td>

            <td><input type="text" name="n_name" class="inputtext" value="<?php echo $row['n_name'] ?>" size="50" maxlength="50" /></td>

          </tr>
          
            


         
 <tr>

            <td class="edit_title">父级分类</td>

            <td>
            <select name="n_sid" >
            	<option value="0" <?php if($row['n_sid']==0) {?> elected="selected" <?php }?>>无</option>
                	<?php

			$query=mysql_query('select * from '.$language.'_pro_class where n_sid=0 order by n_order,n_id');

			if (mysql_num_rows($query)>0){

			while($roww=mysql_fetch_array($query)){
			?>
       
           <option value="<?php echo $roww['n_id']?>" ><?php echo $roww['n_name']?></option>
            
				<?php
               
                 
    
			}

			}

			

			?>
            </select>
            </td>

          </tr>
        
         
          <tr>

            <td class="edit_title">分类排序：</td>

            <td><input type="text" name="n_order" class="inputtext" value="<?php echo $row['n_order'] ?>" size="10" maxlength="10" /></td>

          </tr>
          
          
          

          <tr>

            <td class="edit_title" height="30">&nbsp;</td>

			<td><input type="submit" name="button" class="button" value=" 保存 " />&nbsp;&nbsp;<input type="button" name="button" value=" 返回 " class="button" onclick="history.back();" /></td>

          </tr>

        </table>

      </form>

    </div>
    
      <script type="text/javascript">
	  document.form1.n_sid.value="<?php echo $row['n_sid']?>";
 	  </script>
      

	<?php

	}

	else{

	?>

	<div class="view">

		<h1>产品分类管理<a href="javascript:location.reload();">刷新</a></h1>

	    <table width="100%" border="0" cellpadding="0" cellspacing="0">

        	<tr class="v_title">

                <td width="41%">分类名称</td>
 
             	<td width="12%">分类排序</td>
                
 
				<td width="22%">操作</td>

        	</tr>

			<?php

			$query=mysql_query('select * from '.$language.'_pro_class where n_sid=0  order by n_order,n_id');

			if (mysql_num_rows($query)>0){

				$str='';

				while($row=mysql_fetch_array($query)){

					$str.='<tr onmouseover="this.className=\'view_trover\';" onmouseout="this.className=\'view_trout\';">';

					$str.='<td style="text-align:left; padding-left:20px;">'.$row['n_name'].'</td>';
 
					$str.='<td><div class="inputorder" id="inputorder_'.$row['n_id'].'" contenteditable="true" onblur="Ordern(\'pro_class\','.$row['n_id'].')">'.$row['n_order'].'</div></td>';

					

					$str.='<td><a href="?meter=1&id='.$row['n_id'].'">修改</a> | <a href="?act=delete&id='.$row['n_id'].'" >删除</a></td>';

					$str.='</tr>';
					
					
					 $query2=mysql_query('select * from '.$language.'_pro_class where n_sid='.$row['n_id'].' order by n_order,n_id');

					if (mysql_num_rows($query2)>0){
		
					while($row2=mysql_fetch_array($query2)){
						
						$str.='<tr onmouseover="this.className=\'view_trover\';" onmouseout="this.className=\'view_trout\';">';
		
						$str.='<td style="text-align:left; padding-left:30px;">&nbsp;&nbsp;--'.$row2['n_name'].'</td>';
 						$str.='<td style="padding:2px 0px;"><div class="inputorder" id="inputorder_'.$row2['n_id'].'" contenteditable="true" onblur="Order(\'pro_class\','.$row2['n_id'].')">'.$row2['n_order'].'</div></td>';
		
				
						$str.='<td><a href="?meter=1&id='.$row2['n_id'].'">修改</a> | <a href="?act=delete&id='.$row2['n_id'].'" >删除</a></td>';
		
						$str.='</tr>';
						
					 
		 
					}
		
					}
					
					
					
					
					

				$col++;
				
				

				}
 

			}
			
			echo $str;

			?>

		</table>

	</div><br />

    <div class="edit">

      <h1>&nbsp;</h1>

      <form method="post" action="?act=add" onsubmit="return CheckProClass(this);">

        <table width="100%" border="0" cellpadding="0" cellspacing="0">

          <tr>

            <td class="edit_title">分类名称：</td>

            <td><input type="text" name="n_name" class="inputtext" size="50" maxlength="50" /></td>

          </tr>

 

             <tr>          

            <td class="edit_title">父级分类</td>

            <td>
            <select name="n_sid" >
            	<option value="0" <?php if($row['n_sid']==0) {?> elected="selected" <?php }?>>无</option>
                	<?php

			$query=mysql_query('select * from '.$language.'_pro_class where n_sid=0 order by n_order,n_id');

			if (mysql_num_rows($query)>0){

			while($row=mysql_fetch_array($query)){
			?>
       
           <option value="<?php echo $row['n_id']?>" ><?php echo $row['n_name']?></option>
            
			<?php
                
    
			}

			}

			

			?>
            </select>
            </td>

          </tr>
        
  

          
          <tr>

            <td class="edit_title">分类排序：</td>

            <td><input type="text" name="n_order" class="inputtext" size="10" maxlength="10" /></td>

          </tr>

          <tr>

            <td class="edit_title" height="30">&nbsp;</td>

			<td><input type="submit" name="button" class="button" value=" 添加 " /></td>

          </tr>

        </table>

      </form>

    </div>

	<?php } ?>

</div>

 

</body>

</html>